package com.example.pcbcsmbackend.repository;

import com.example.pcbcsmbackend.entity.OrderDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface OrderDetailRepository extends JpaRepository<OrderDetail, Integer> {
    // 根据订单ID查找订单详情
    List<OrderDetail> findByOrder_OrderId(Integer orderId);
    
    // 根据商品ID查找订单详情
    List<OrderDetail> findByProductId(Integer productId);
    
    // 根据订单ID删除订单详情
    @Transactional
    void deleteByOrder_OrderId(Integer orderId);
    
    // 根据订单ID列表批量删除订单详情
    @Transactional
    void deleteByOrder_OrderIdIn(List<Integer> orderIds);
    
    // 根据商品ID删除订单详情
    @Transactional
    void deleteByProductId(Integer productId);
    
    // 根据商品ID列表批量删除订单详情
    @Transactional
    void deleteByProductIdIn(List<Integer> productIds);
} 